//定义异常类并继承js原生的error
class HttpException extends Error {
  constructor(msg = '服务器异常', errorCode = 10000, code = 400) {
    super()
    this.msg = msg
    this.errorCode = errorCode
    this.code = code
  }
}
class ParameterException extends HttpException {
  constructor(msg, errorCode) {
    super()
    this.msg = msg || '参数错误'
    this.error_code = errorCode || 10000
  }
}
class Success extends HttpException {
  constructor(msg, errorCode, code) {
    super()
    this.msg = msg || 'ok'
    this.code = 200
    this.error_code = 200
  }
}
class NotFound extends HttpException {
  constructor(msg, errorCode) {
    super()
    this.msg = msg || '资源未找到'
    this.code = 200
    this.error_code = errorCode || 400
  }
}
class AuthFailed extends HttpException {
  constructor(msg, errorCode) {
    super()
    this.msg = msg || '授权失败'
    this.code = 401
    this.error_code = errorCode || 401
  }
}

module.exports = {
  HttpException,
  ParameterException,
  Success,
  NotFound,
  AuthFailed,
}
